package com.customer.controller.web;

import com.customer.service.IntegrationHistoryService;
import com.nameless.entity.Client;
import com.nameless.entity.IntegrationHistory;
import com.nameless.vo.IntegrationHistoryVo;
import com.nameless.vo.Result;
import com.nameless.vo.pay.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2023/03/04 14:58
 * @Description
 */
@Api(value = "钱包充值使用记录", tags = {"-*- coding:utf-8 -*-"})
@RestController
@RequestMapping("client/IntegrationHistory/web")
@Slf4j
public class IntegrationHistoryController {

    @Autowired
    private IntegrationHistoryService integrationHistoryService;
    @ApiOperation(value = "查找初始化钱包记录", notes = "", httpMethod = "GET")
    @GetMapping("getInitialHistory")
    public Client getInitialHistory(){
        return integrationHistoryService.getInitialHistory();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "amount", value = "", required = true)
    })
    @ApiOperation(value = "充值钱包创建微信支付/支付宝支付", notes = "", httpMethod = "GET")
    @GetMapping("createKryptonGold/{amount}/{status}")
    public Result<Map<String,Object>> createKryptonGold(@PathVariable String amount,@PathVariable Integer status){
        return integrationHistoryService.createKryptonGold(amount,status);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "orderNo", value = "", required = true)
    })
    @ApiOperation(value = "支付已经创建订单的信息", notes = "", httpMethod = "GET")
    @GetMapping("payExistingOrder/{orderNo}/{status}")
    public Result<Map<String,Object>> payExistingOrder(@PathVariable String orderNo ,@PathVariable Integer status){
        return integrationHistoryService.payNative(orderNo,status);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "orderNo", value = "", required = true)
    })
    @ApiOperation(value = "查询微信支付的成功信息", notes = "", httpMethod = "GET")
    @GetMapping("queryPayStatus/{orderNo}/{status}")
    public Result<String> queryPayStatus(@PathVariable String orderNo ,@PathVariable Integer status){
        return integrationHistoryService.queryPayStatus(orderNo,status);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "orderNo", value = "", required = true)
    })
    @ApiOperation(value = "查询微信支付的成功信息", notes = "", httpMethod = "GET")
    @GetMapping("cancelPayment/{orderNo}")
    public Result<String> cancelPayment(@PathVariable String orderNo){
        return integrationHistoryService.cancelPayment(orderNo);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "orderNo", value = "", required = true)
    })
    @ApiOperation(value = "查询该用户所有明细", notes = "", httpMethod = "GET")
    @GetMapping("getOne")
    public Result<List<IntegrationHistory>> getList(){
        List<IntegrationHistory> list = integrationHistoryService.getListByClientId();
        return Result.success(list);
    }

    @ApiOperation(value = "使用账户余额进行租车--创建积分历史", notes = "", httpMethod = "GET")
    @PostMapping("payCarCreateHistory")
    public Result<String> payCar(@RequestBody IntegrationHistoryVo integrationHistoryVo){
        String list = integrationHistoryService.payCar(integrationHistoryVo);
        return Result.success(list);
    }

    @ApiOperation(value = "支付成功--修改积分历史为已支付--修改客户表中的金额", notes = "", httpMethod = "GET")
    @GetMapping("payCarUpdateClient/{orderNo}")
    public Result<String> payCarUpdateClient(@PathVariable String orderNo){
        boolean b = integrationHistoryService.payCarSuccess(orderNo);
        return b?Result.success("修改账号余额成功"): Result.error("修改账号余额失败");
    }
}
